/* -----------------------------------------------------------------------
 * Don't forget to include the following lines in your makefile:
 *
 * testFileName: testFileName.c dominion.o rngs.o
 *      gcc -o testFileName -g  testFileName.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 *
 *  testing the smithy card
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1
#define NUM_TESTS 10

int main() {
    int i,j;
    int seed = 1000;
    int numPlayer;
    int p, q, r, precount, postcount, thisPos, game;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

    srand(time(NULL));

#if (NOISY_TEST == 1)
    printf ("TESTING smithy card:\n");
#endif
    for (i = 0; i < NUM_TESTS; i++)
    {
#if (NOISY_TEST == 1)
        printf("Test number %d.\t", i);
#endif

        numPlayer = (rand() % MAX_PLAYERS); //use random # players
        game = initializeGame(numPlayer, k, seed, &G); // initialize a new game
        assert(game == 0);
        for(p = 0; p < numPlayer; p++){
#if (NOISY_TEST == 1)
            printf("Test player %d.\n", p);
#endif
            G.whoseTurn = p;
            r = 0;
            if(G.handCount[p] == 0){
                while(r < (rand() % MAX_HAND)){
                    drawCard(p,&G);
                }
            }

            precount = G.handCount[p]; //# cards in hand before
            thisPos = rand() % G.handCount[p]; //random # position for smithy
            q = cardEffect(smithy,0,0,0,&G,thisPos,0);
            assert(q == 0);
            assert(G.handCount[p] == (precount+2)); //cards in hand after should be 2 more than before once smithy is discarded
#if (NOISY_TEST == 1)
            printf("Test passed!\n");
#endif
        }
    }

    printf("All tests passed!\n");

    return 0;
}
/*reference code
smithy: draws 3 cards and discards the current card
struct gameState* smithyCard(struct gameState *state, int handPos){
    //+3 Cards
    int i = 0;
    int currentPlayer = whoseTurn(state);

    for (i; i <= 3; i++){
        drawCard(currentPlayer, state);
    }

    //discard card from hand
    discardCard(handPos, currentPlayer, state, 0);
    return state;
}
      */
